<?php
namespace Home\Controller;
use Think\Controller;
class AddemploymentController extends Controller {
    // 后台登录页
    public function index(){
        if(isset($_SESSION['admin'])){ 
            $position = D('position');
            $positionList = $position->select();            
            $this->assign('arrP',$positionList);
            $this->display();
        }else{
            $url = 'http://localhost/person/index.php/Home/Index/manage';
            header("location: $url");
        }
    }

     //添加职位
    public function employmentAdd($title,$position_id,$salary,$info){
        if($title == null || $position_id  == null || $salary  == null|| $info  == null){
            $result = array(
                'code'=> '1',
                'ext'=> 'error'
            );
            echo json_encode($result);
            return;
        }

        $info1 = D("info");
        $data['title'] = $title;
        $data['position_id'] = $position_id;
        $data['salary'] = $salary;
        $data['info'] = $info;
         if($info1->create($data)){
            $id = $info1->add();
            if($id){
                $result = array(
                    'code' => '0',
                    'ext' => 'success'
                );
                echo json_encode($result);
            }
        }
    }
      //退出
    public function doLogout(){
        $_SESSION = array();
        if(isset($_COOKIE[session_name()])){
            setcookie(session_name(),'',time()-1,'/');
        }
        session_destroy();
        $this->redirect('Index/index');
    }



}
